/*
 * httphandlelastmodified.cpp
 *
 *  Created on: Apr 27, 2009
 *      Author: kuncai
 */
#ifndef HTTPHANDLELASTMODIFIED_H_
#define HTTPHANDLELASTMODIFIED_H_
#include <sys/stat.h>
#include <unistd.h>
#include "log.h"
#include "httphandle.h"
#include "date.h"
using namespace Http;
class HttpHandleLastModified: public HttpHandle{
	void ProcessRequest(HttpRequest* httpRequest, HttpResponse* httpResponse){
		//read url file
		string sFilename = "."+httpRequest->GetParam("url"); 
		struct stat filestat;
		Log::Debug(" Last Modified\n");
		if (stat(sFilename.c_str(),&filestat)==0){
			//success
			time_t time = filestat.st_mtime;
			Date date(time);
			httpResponse->SetHeader(Http::LastModified,date.ToString());
			if(successor != NULL){
				successor->ProcessRequest(httpRequest, httpResponse);
			}
		}
		else{
			Log::Info("Last Modified error,errormsg:%s\n",strerror(errno));
			if(error != NULL){
				error->ProcessRequest(httpRequest, httpResponse);
			}
		}
		//end read url file

	}
};
#endif /* HTTPHANDLELASTMODIFIED_H_ */
